#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/knot/files/knot.init,v 1.2 2013/08/21 09:23:59 scarabeus Exp $

name="knotd"
command="/usr/sbin/knotd"
command_args="-d ${KNOTD_OPTS}"
start_stop_daemon_args="--wait 5"
required_files=/etc/knot/knot.conf
extra_started_commands="reload"
description_reload="Reload configuration and changed zones"

depend() {
	need net
}

start_pre() {
	checkpath -d -m 0751 -o knot:knot /run/knot/
	checkpath -d -m 0750 -o knot:knot /var/lib/knot/
}

stop() {
	ebegin "Stopping $name"
	/usr/sbin/knotc stop >/dev/null 2>&1
	# Mark service as stopped if remote control was successful
	if [ $? -eq 0 ]; then
		start-stop-daemon --stop --quiet --pidfile /run/knot/knot.pid
	fi
	eend $?
}

reload() {
	ebegin "Reloading $name"
	/usr/sbin/knotc reload >/dev/null
	eend $?
}
